function singletonIfy(className):ProxyConstructor{
    return new Proxy(className.prototype.constructor,{
        construct(target: ProxyConstructor, argArray: any, newTarget?: any): object {
            if(!this.instance){
                // @ts-ignore
                this.instance = new target(...argArray);
            }
            return this.instance;
        }
    })
}

class MyClass{
    private readonly msg: string;
    constructor(msg) {
        this.msg = msg;
    }
    printMsg():void{
        console.log(this.msg);
    }
}

let MySingletonClass;
MySingletonClass = singletonIfy(MyClass);
const obj1 = new MySingletonClass('first');
obj1.printMsg(); //first
const obj2 = new MySingletonClass('second');
obj2.printMsg(); //first

